Ext.define('Identification', {
    extend: 'Ext.data.Model',
    fields: [
        "Id"
		, "IdentType"   //证件类型
		, "IdentNumber"   //证件编号
		, "IdentAuthority"   //发证单位
		, "Period"   //有效期
		, "StartDate"   //起始日期
		, "EndDate"   //截止日期
        , "EmpId"   //员工Id
        , "EmpName"   //员工姓名
    ],
    idProperty: "Id"
});

Ext.define('SHApp.EmployeeInfo.Identification.Grid', {
    extend: 'BLBTSystem.grid',
    alias: 'shapp.employeeinfo.grid',
    requires: ['SHApp.EmployeeInfo.Identification.Form'],
    txtIdentTypeID: 'txtIdentType',
    txtIdentNumberID: 'txtIdentNumber',
    dataModel: "Identification",
    dataUrl: "api/identification?format=json",
    empId: "",
    empName: "",
    initComponent: function () {
        var me = this;
        Ext.apply(this);
        me.btnAddID += me.id;
        me.btnEditID += me.id;
        me.btnDeleteID += me.id;
        me.btnLockID += me.id;
        me.btnUnLockID += me.id;
        me.txtIdentTypeID += me.id;
        me.txtIdentNumberID += me.id;
        this.creatTbar();
        this.creatColumns();
        this.callParent(arguments);
        this.checkBtnPermission(me.pvalue);
    },
    creatColumns: function () {
        var me = this;
        me.columns = [
            {
                text: "Id",
                flex: 1,
                dataIndex: 'Id',
                sortable: false,
                hidden: true
            }, {
                text: "证件类型",
                width: 100,
                dataIndex: 'IdentType',
                sortable: true
            }, {
                text: "证件编号",
                width: 100,
                dataIndex: 'IdentNumber',
                sortable: true
            }, {
                text: "发证单位",
                width: 100,
                dataIndex: 'IdentAuthority',
                sortable: true
            }, {
                text: "有效期",
                width: 100,
                dataIndex: 'Period',
                sortable: true
            }, {
                text: "起始日期",
                width: 100,
                dataIndex: 'StartDate',
                sortable: true,
                renderer: formatDate
            }, {
                text: "截止日期",
                width: 100,
                dataIndex: 'EndDate',
                sortable: true,
                renderer: formatDate
            }
		]
    },
    creatTbar: function () {
        var me = this;
        me.tbar = [
            Ext.create("BLBTSystem.CmbYesNo", {
                fieldLabel: "证件类型:",
                fields: ["text"],
                data: [["身份证"], ["护照"], ["学生证"], ["军官证"], ["驾照"]],
                valueField: "text",
                displayField: "text",
                name: "IdentType",
                id: me.txtIdentTypeID,
                maxLength: 50,
                labelWidth: 60,
                width: 180,
                forceSelection: false,
                value: "身份证"
            }), {
                xtype: 'textfield',
                disabled: false,
                fieldLabel: '证件编号:',
                labelWidth: 60,
                name: 'IdentNumber',
                id: me.txtIdentNumberID,
                width: 180
            }, ' ', {
                xtype: 'button',
                text: '查询',
                iconCls: 'icon-btn-search',
                handler: function () {
                    me.clearFilters();
                    me.addFilter("EmpId", me.empId);
                    var vIdentType = Ext.getCmp(me.txtIdentTypeID).getValue();
                    if (vIdentType && vIdentType.length > 0) {
                        me.addFilter("IdentType", vIdentType);
                    }
                    var vIdentNumber = Ext.getCmp(me.txtIdentNumberID).getValue();
                    if (vIdentNumber && vIdentNumber.length > 0) {
                        me.addFilter("IdentNumber", vIdentNumber);
                    }
                    me.loadByFilter();
                }
            }, '->', {
                xtype: 'button',
                text: '添加',
                id: me.btnAddID,
                iconCls: 'icon-btn-add',
                handler: function () {
                    var win = me.getForm('SHApp.EmployeeInfo.Identification.Form');
                    win.loadRecord(new Identification({ Id: null, IdentType: "身份证", StartDate: new Date(), EndDate: new Date(), Period: "0年", EmpId: me.empId, EmpName: me.empName }));
                    win.Show("添加");
                }
            }, ' ', {
                xtype: 'button',
                disabled: true,
                id: me.btnEditID,
                text: '修改',
                iconCls: 'icon-btn-edit',
                handler: function () {
                    var rs = me.getSelectionModel().getSelection();
                    if (rs) {
                        if (rs.length > 0) {
                            rs[0].data.StartDate = formatDate(rs[0].data.StartDate);
                            rs[0].data.EndDate = formatDate(rs[0].data.EndDate);
                            me.EditData(me.getForm('SHApp.EmployeeInfo.Identification.Form'));
                        }
                    }
                }
            }, ' ', {
                xtype: 'button',
                disabled: true,
                id: me.btnDeleteID,
                text: '删除',
                iconCls: 'icon-btn-delete',
                handler: function () {
                    me.DeleteData();
                }
            }
        ]
    }
});

